<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改产品图片')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-images-add">
		<input id="imagesId" name="imagesId" type="hidden"/>
		<div class="form-group">
			<label class="col-sm-3 control-label">图片名称：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="imagesName" id="imagesName"required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">图片选择：</label>
			<div class="col-sm-8">
				<select class="form-control" name="urlId" onchange="imagesNodeId(this)">
					<option th:each="url:${url}" th:value="${url.urlId}">[[${url.urlId}]]</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label"></label>
			<div class="col-sm-8" id="imagesDivId">

			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
	var prefix = ctx + "product/images";

	$("#form-images-add").validate({
		onkeyup: false,
		rules:{
			typeSort:{
				digits:true
			},
		},
		focusCleanup: true
	});

	function submitHandler() {
		if ($.validate.form()) {
			$.operate.save(prefix + "/add", $('#form-images-add').serialize());
		}
	}

	function imagesNodeId(obj) {
		$.ajax({
			url: prefix + "/changeImagesUrl",
			data:{urlId:obj.value},
			dataType:"json",
			type:"post",
			async:"true",
			success:function (data) {
				if(data.code == 0){
					$("#imagesDivId").empty();
					// $("#imagesUrlId").attr("src",data.data.imagesUrl);
					$("#imagesDivId").append("<img src=\""+data.data.urlSrc+"\" width=\"300px\" height=\"300px\">")
				}else {
					console.log(data.msg);
				}
			}
		});
	}
</script>
</body>
</html>
